import { useCallback, useEffect, useState } from "react";
const useSyncCallback = (callbacks: Function) => {
  const [proxyState, setProxyState] = useState({ current: false });

  const Func = useCallback(() => {
    setProxyState({ current: true });
  }, [proxyState]);

  useEffect(() => {
    if (proxyState.current === true) {
      console.log("change");
      setProxyState({ current: false });
    }
  }, [proxyState]);

  useEffect(() => {
    proxyState.current && callbacks();
  });

  return Func;
};

export default useSyncCallback;
